#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define MINH -10001
int H[1001], size;
void MakeHeap();
void Insert(int num);
int main()
{
    int N, M, i,input;
    MakeHeap();
    scanf("%d", &N);
    for (i = 0; i < N;i++)
    {
        scanf("%d", &input);
        Insert(input);
    }
    scanf("%d", &M);
    for (int j = 0; j < M;i++)
    {
        scanf("%d", input);
        printf("%d", H[input]);
        while(input<1)
        {
            input = input / 2;
            printf(" %d", H[input]);
        }
    }

    return 0;
}

void MakeHeap()
{
    size = 0;
    H[size] = -1;
}
void Insert(int num)
{
    int i;
    for (i=++size; H[i/2] > num;i/=2)
        H[i] = H[i / 2];
    H[i] = num;
}